﻿using System;
using log4net;
using log4net.Config;
using MdcService.Static;

namespace MdcService.Log
{
    public class Log4NetLogger:ILogging
    {
        public Log4NetLogger()
        {
            
            BasicConfigurator.Configure(new log4net.Appender.FileAppender
            {
                File = "log.txt",
                Layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger %ndc - %message%newline"),
            });
        }

        public void Debug(object sender, string message, Exception t = null)
        {
            var log = LogManager.GetLogger(sender.GetType());
            
            log.Debug(message, t);
        }

        public void Info(object sender, string message, Exception t = null)
        {
            var log = LogManager.GetLogger(sender.GetType());
            log.Info(message, t);
        }

        public void Warn(object sender, string message, Exception t = null)
        {
            var log = LogManager.GetLogger(sender.GetType());
            log.Warn(message, t);
        }

        public void Error(object sender, string message, Exception t = null)
        {
            var log = LogManager.GetLogger(sender.GetType());
            log.Error(message, t);
        }

        public void Fatal(object sender, string message, Exception t = null)
        {
            var log = LogManager.GetLogger(sender.GetType());
            log.Fatal(message, t);
        }
    }
}
